package com.foreknow.demo5Exercise1;

/**
 * 2.2 有2个属性：长length、宽width
 * 2.3 通过构造方法Rectangle(int width, int length)，分别给两个属性赋值
 * 2.4 创建一个Rectangle对象，并输出相关信息
 */

public class Rectangle {

    private int x;
    private int y;

    public Rectangle() {

    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getArea() {//求面积
        int area = x*y;
        return area;
    }

    public int getPer() {//求周长
        int per = (x+y)*2;
        return per;
    }

    public void showAll() {
        System.out.println("长为：" + getX());
        System.out.println("宽为：" + getY());
        System.out.println("面积为：" + getArea());
        System.out.println("周长为：" + getPer());
    }

    private int width;
    private int length;

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getLength() {
        return length;
    }

    public void setLength(int length) {
        this.length = length;
    }

    public Rectangle(int width, int length) {
        this.width = width;
        this.length = length;
    }

    public static void main(String[] args) {
        Rectangle r = new Rectangle();
        r.setX(8);
        r.setY(5);
        int area = r.getArea();
        System.out.println("面积 = " + area);
        int per = r.getPer();
        System.out.println("周长 = " + per);
        r.showAll();
        Rectangle r1 = new Rectangle(10,8);
        System.out.println("长为:" + r1.width + "宽为：" + r1.length);
    }
}
